
var ctr = null; 
//添加控件
function addSceneCtr(id){
	$("#accordion").accordion({
        heightStyle: "fill"
    });
	 //var div = document.getElementById(id);
	 //var object = document.createElement("object");
	 //object.classid = "CLSID:D4F3CC6C-56A0-466D-A862-283C120CAF04";
	 //object.id = "ctr";
	 //object.style.width = '100%';
	 //object.style.height = '100%';
	 //object.type = "application/x-cm-3d";
	 //div.appendChild(object);
	 //获取控件
	 ctr = document.getElementById("ctr");
	 //场景启动
     setTimeout(function() {
        ctr.InitFromSceneFile("scene.xml");  
        ctr.Render();
    },20);
};

//sceneControl
function SceneControl() {
	//htmlWindow的有关参数
	this.htmlWindowParam = function(){
		return ctr.new_HtmlWindowParam;
	};
	//CameraAnimationKeyPoint
	this.cameraAnimationKeyPoint = function(){
		return ctr.new_CameraAnimationKeyPoint;
	};
	//CameraAnimationKeyPointMap
	this.cameraAnimationKeyPointMap = function(){
		return ctr.new_CameraAnimationKeyPointMap;
	};
	//GlobalControlPoint
	this.globalControlPoint = function(){
		return ctr.new_GlobalControlPoint;
	};
	//ModelFlyPath
	this.modelFlyPath = function(){
		return ctr.new_ModelFlyPath;
	};
	//ToolsManager
	this.toolsManager = function(){
		return ctr.ToolsManager;
	};
	//widgetParam
	this.widgetParam = function(){
		return ctr.new_WidgetParam;
	};
	//事件连接
	this.AttachEvent = function(Event, func){
		ctr.attachEvent(Event, func);
	};
	//ModelLayer
	this.ModelLayer = function(){
		return ctr.new_ModelLayer;
	};
	//IntVec
	this.IntVec = function(){
		return ctr.new_IntVec;
	};
	//Vector
	this.Vector3 = function(){
		return ctr.new_Vector3;
	};
	//Quaternion
	this.Quaternion = function(){
		return ctr.new_Quaternion;
	};
	//MainCamera
	this.MainCamera = function(){
		return ctr.MainCamera;
	};
	//Matrix4
	this.Matrix4 = function(){
		return ctr.new_Matrix4;
	};
	//PM
	this.pMViewManager = function(){
		return ctr.PMViewManager;
	};
	//LoadScene
	this.initFromSceneFile = function(file){
		ctr.InitFromSceneFile(file);
	};
	//ReloadScene
	this.reloadFromSceneFile = function(file){
		ctr.ReloadFromSceneFile(file);
	};
	//render
	this.render = function(){
		ctr.Render();
	};
	//point
	this.point = function(){
		return ctr.new_Point;
	};
	//linestring
	this.lineString = function(){
		return ctr.new_LineString;
	};
	//空间参考系
	this.SpatialReference = function(){
		return ctr.new_SpatialReference;
	};
	//stringVec
	this.StringVec = function(){
		return ctr.new_StringVec;
	};
	//camera
	this.mainCamera = function(){
		return ctr.MainCamera;
	};
	//模型源
	this.modelSource = function(){
		return ctr.new_ModelSource;
	};
	//数据库连接参数
	this.dbConnectParam = function(){
		return ctr.new_DBConnectParam;
	};
	
};

//sceneView
function SceneView() {
	this.sceneView = ctr.SceneView;
	//开始飞行
	this.startCameraAnimation = function(){
		this.sceneView.StartCameraAnimation();
	};
	//停止飞行
	this.stopCameraAnimation = function(){
		this.sceneView.StopCameraAnimation();
	};
	//相机动画关键点
	this.cameraAnimationKeyPoints = function(pointMap){
		this.sceneView.CameraAnimationKeyPoints = pointMap;
	};
	//添加模型飞行路径
	this.addModelFlyPath = function(pahtName, flyPath){
		this.sceneView.AddModelFlyPath(pahtName, flyPath);
	};
	//开始模型飞行
	this.startModelFly = function(pathName){
		this.sceneView.StartModelFly(pathName);
	};
	//飞行定位
	this.flyTo =  function(lon, lat, heading, tilt, altitude){
		this.sceneView.FlyTo(lon, lat, heading, tilt, altitude, 5000);
	};
	//获得当前鼠标点经纬高
	this.getCurrentCursorPos = function(bool){
		return this.sceneView.GetCurrentCursorPos(bool);
	};
	//暂停飞行
	this.pauseCameraAnimation = function(){
		this.sceneView.PauseCameraAnimation();
	};
	//继续飞行
	this.continueCameraAnimation = function(){
		this.sceneView.ContinueCameraAnimation();
	};
	//获得层编辑
	this.getLayerEditor = function(key){
		return this.sceneView.GetLayerEditor(key);
	};
	//添加视口
	this.addViewport = function(name,zorder,left,top,width,height,tilt,heading){
		return this.sceneView.AddViewport(name,zorder,left,top,width,height,tilt,heading);
	};
	//移除视口
	this.removeViewport = function(name){
		return this.sceneView.RemoveViewport(name);
	};
	//设置相机操作器求交模型
	this.setCameraManipulatorIntersectModel = function(flag){
		this.sceneView.setCameraManipulatorIntersectModel(flag);
	};
	//开启第一人称操作器
	this.enableFirstPersonCameraManipulator = function(lon, lat, alt, timeSpan){
		this.sceneView.EnableFirstPersonCameraManipulator(lon, lat, alt, timeSpan);
	};
	//关闭第一人称操作器
	this.disableFirstPersonCameraManipulator = function(){
		this.sceneView.DisableFirstPersonCameraManipulator();
	};
};

//scenemanager
function SceneManager() {
	this.sceneManager = ctr.SceneManager;
	//设置图层显隐
    this.layerVisible = function(id){
		var isChecked = $("#"+id).prop("checked");
		this.sceneManager.SetLayerVisible(id, isChecked); 
	};
	//创建HUDLabel
	this.createHUDLabel = function(name, tempName){
		return this.sceneManager.CreateHUDLabel(name, tempName);
	};
	//关闭HUDLabel
	this.destoryHUDLabel = function(name){
		this.sceneManager.DestoryHUDLabel(name);
	};
	//获得指定id的节点
	this.getSceneNode = function(id){
		return this.sceneManager.GetSceneNode(id);
	};
	//得到场景根节点
	this.getRootSceneNode = function(typ){
		return this.sceneManager.GetRootSceneNode(typ);
	};
	//创建模型节点
	this.createObjectModel = function(modelPath){
		return this.sceneManager.CreateObjectModel(modelPath);
	};
	//获取相对层
	this.relativeLayerGroup = function(){
		return this.sceneManager.RelativeLayerGroup;
	};
	//设置图层透明度
	this.setImageLayerTransparency = function(alpha){
		this.sceneManager.SetImageLayerTransparency(alpha);
	};
	//粒子系统
	this.createParticleSystem = function(temp){
		return this.sceneManager.CreateParticleSystem(temp);
	};
	//销毁粒子特效
	this.destroyParticleSystem = function(system){
		this.sceneManager.DestroyParticleSystem(system);
	};
	//天气
	this.createWeather = function(typ){
		this.sceneManager.CreateWeather(typ);
	};
	//清除天气
	this.clearWeather = function (){
		this.sceneManager.ClearWeather();
	};
	//改变地形
	this.modifyDEM = function(name,LS, SR, height){
		this.sceneManager.ModifyDem(name,LS, SR, height);
	};
	//恢复地形
	this.recoverDEM = function(name){
		this.sceneManager.RecoverDem(name);
	};
	//创建模型
	this.createModelObject1 = function(filename){
		return this.sceneManager.CreateModelObject1(filename);
	};
};


//HtmlWindow
function HtmlWindow() {
	this.htmlWindow = ctr.HtmlWindow;
	//弹出窗口（通过参数IsTitle来判断是弹出有标题窗口还是无标题窗口）
	this.popUpHtmlWindow = function(param){
		this.htmlWindow.PopupHtmlWindow(param);
	};
	//关闭窗口
	this.closeWindow = function(id){
		this.htmlWindow.CloseHtmlWindow(id);
	};
	
	
};

//UITrayManager
function UITrayManager() {
	this.uITrayManager = ctr.WidgetManager;
	//button
	this.createButton = function(widgetParam){
		return this.uITrayManager.createButton(widgetParam);
	};
	//textbox
	this.createTextBox = function(widgetParam,height){
		return this.uITrayManager.createTextBox(widgetParam,height);
	};
	//ThickSelectMenu
	this.createThickSelectMenu = function(widgetParam, maxItemShown){
		return this.uITrayManager.createThickSelectMenu(widgetParam, maxItemShown);
	};
	//LongSelectMenu
	this.createLongSelectMenu = function(widgetParam, boxWidth, maxItemShown){
		return this.uITrayManager.createLongSelectMenu(widgetParam, boxWidth, maxItemShown);
	};
	//Label
	this.createLabel = function(widgetParam){
		return this.uITrayManager.createLabel(widgetParam);
	};
	//Separator
	this.createSeparator = function(widgetParam){
		this.uITrayManager.createSeparator(widgetParam);
	};
	//ThickSlider
	this.createThickSlider = function(widgetParam, valueBoxWidth){
		return this.uITrayManager.createThickSlider(widgetParam, valueBoxWidth);
	};
	//LongSlider
	this.createLongSlider = function(widgetParam, trackWidth, valueBoxWidth){
		return this.uITrayManager.createLongSlider(widgetParam, trackWidth, valueBoxWidth);
	};
	//LongSelectMenuNoWidth
	this.createLongSelectMenuNoWidth = function(widgetParam, boxWidth, maxItemShown){
		return this.uITrayManager.createLongSelectMenuNoWidth(widgetParam, boxWidth, maxItemShown);
	};
	//LongSliderNoWidth
	this.createLongSliderNoWidth = function(widgetParam, trackWidth, valueBoxWidth){
		return this.uITrayManager.createLongSliderNoWidth(widgetParam, trackWidth, valueBoxWidth);
	};
	//ParamsPanelWithLines
	this.createParamsPanelWithLines = function(widgetParam, lines){
		return this.uITrayManager.createParamsPanelWithLines(widgetParam, lines);
	};
	//ParamsPanelWithParamNames
	this.createParamsPanelWithParamNames = function(widgetParam, paramNames){
		return this.uITrayManager.createParamsPanelWithParamNames(widgetParam, paramNames);
	};
	//CheckBox
	this.createCheckBox = function(widgetParam){
		return this.uITrayManager.createCheckBox(widgetParam);
	};
	//DecorWidget
	this.createDecorWidget = function(widgetParam,templateName){
		this.uITrayManager.createDecorWidget(widgetParam,templateName);
	};
	//ProgressBar
	this.createProgressBar = function(widgetParam,commentBoxWidth){
		return this.uITrayManager.createProgressBar(widgetParam,commentBoxWidth);
	};
	//通过name关闭
	this.destroyWidgetByName = function(name){
		this.uITrayManager.destroyWidgetByName(name);
	};
	//删除同一个容器内的widget
	this.destroyAllWidgetsInTray = function(locationID){
		this.uITrayManager.destroyAllWidgetsInTray(locationID);
	};
	//删除全部widget
	this.destroyAllWidgets = function(){
		this.uITrayManager.destroyAllWidgets();
	};
};

//数学工具
function MathUtility(){
	this.mathUtility = ctr.MathUtility;
	//从Lat Lon Alt Heading Pitch Roll Scale转四维矩阵
	this.computeMatrixFromLonLatAltEulerAngleScale = function(Lat, Lon, Alt, Heading, Pitch, Roll, Scale){
		return this.mathUtility.ComputeMatrixFromLonLatAltEulerAngleScale(Lat, Lon, Alt, Heading, Pitch, Roll, Scale);
	};	
};





